//
//  TZBasicController.swift
//  weibo_Swift
//
//  Created by 涂真 on 15/12/16.
//  Copyright © 2015年 涂真. All rights reserved.
//

import UIKit

class TZBasicController: UITableViewController,TZVisitorViewDelegate {
    var isLogin = TZUserAccount.isLogin
    override func loadView() {
        isLogin ? super.loadView():setUpVisitorView()
        
    }
    //MARK:设置访客视图
    func setUpVisitorView(){
        view = visitorView
        //指定代理
        visitorView.delegate = self
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnDidClick")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnDidClick")
        
        switch self{
        case is TZHomeController:
            visitorView.rotateCircleView()
            //程序退入后台或者进入前台都会发出通知
            //注册监听
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name:UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        case is TZMessageController:
            visitorView.setupVisitorView("visitordiscover_image_message", hintText: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        case is TZDiscoverController:
            visitorView.setupVisitorView("visitordiscover_image_message", hintText: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        case is TZFrofileController:
            visitorView.setupVisitorView("visitordiscover_image_profile", hintText: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        default:
            break
        
        }
    }
    //析构函数移除通知
    deinit{
        if self is TZHomeController{
        NSNotificationCenter.defaultCenter().removeObserver(self)
        
        }
    }
    
    //MARK: - 后台前台切换时调用
    //退入后台
    func didEnterBackground(){
    
        visitorView.pauseAnimation()
    }
    //进入前台
    func didBecomeActive(){
    
        visitorView.resumeAnimation()
    }
    
    //MARK: - 懒加载
    lazy var visitorView:TZVisitorView = TZVisitorView()
    
    //MARK: - TZVisitorViewDelegate的代理方法
    func loginBtnDidClick() {
        let oauthC = TZOauthController()
        self.presentViewController(UINavigationController(rootViewController: oauthC), animated: true) { () -> Void in
            
        }
        
    }
    func registerBtnDidClick() {
        print("注册")
    }
        
}
